package com.kkd.kkdapp.view.rainView;

import java.util.Random;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;

public class RainItem {

	private int width;
	public int height;

	private float startX;
	public float startY;
	private float sizeX;
	private float sizeY;
	private float opt;
	private Paint paint;
	private Random random;
	private int flag = 0;
	private int size = 20;
	private int color;
	private Bitmap mBitmap;
	private boolean randColor = false;
	private Context mContext;

	public RainItem(int width, int height) {
		this.width = width;
		this.height = height;
		init();
	}

	public RainItem(int width, int height, int size) {
		this.width = width;
		this.height = height;
		this.size = size;
		init();
	}

	public RainItem(int width, int height, int size, int color,
			Context mContext, int startY) {
		this.width = width;
		this.mContext = mContext;
		this.height = height;
		this.size = size;
		this.color = color;
		init();
		mBitmap = BitmapFactory.decodeResource(mContext.getResources(), color);
		this.startY = startY;
	}

	public RainItem(int width, int height, int size, int color,
			boolean randColor) {
		this.width = width;
		this.height = height;
		this.size = size;
		this.color = color;
		this.randColor = randColor;
		init();
	}

	private void init() {
		random = new Random();
		sizeX = 1 + random.nextInt(size / 2);
		sizeY = 10 + random.nextInt(size);
		startX = random.nextInt(width);
		// opt = 0.2f + random.nextFloat();
		opt = 0.4f + (random.nextFloat() / 3);
		paint = new Paint();
		paint.setAntiAlias(true);
		paint.setFilterBitmap(true);
		paint.setDither(true);
	}

	public void draw(Canvas canvas) {
		canvas.drawBitmap(mBitmap, startX, startY, paint);
	}

	public void move() {
		startY += (sizeY * opt) * 15;
	}
}
